﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using mendian;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.抖音出入库.Service
{
    public class 零售Service
    {
        /// <summary>
        /// 创建零售sku
        /// </summary>
        /// <param name="description"></param>
        /// <param name="ifPreSale"></param>
        /// <param name="price"></param>
        /// <param name="orgId"></param>
        /// <param name="shopId"></param>
        /// <param name="FileName"></param>
        public static void createSku(String description,Boolean ifPreSale,Double price, String orgId, String shopId, String FileName)
        {
            FileService
                .UploadRequest(
                    URL.接口url1 + "/douyin/createSku?description=" + description 
                                                    + "&ifPreSale=" + ifPreSale 
                                                    + "&price=" + price 
                                                    + "&orgId=" + orgId 
                                                    + "&shopId="+ shopId,
                    FileName,
                    Path.GetFileName(FileName),
                    "multipartFile"
                );
        }

        /// <summary>
        /// 取得未发货订单
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public static List<RetailSkuDTO> getUnDeliveryOrder(String orgId, String shopId)
        {
            return
                FunctionHelper.JsonDeserialization<List<RetailSkuDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/getUnDeliveryOrder?orgId=" + orgId + "&shopId=" + shopId
                        )
                    );
        }
        /// <summary>
        /// 根据电话查询历史订单
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public static List<RetailUserOrderDTO> getRetailUserOrderByMobile(String mobile, String orgId, String shopId)
        {
            return
                FunctionHelper.JsonDeserialization<List<RetailUserOrderDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/getRetailUserOrderByMobile?mobile=" + mobile + "&orgId=" + orgId + "&shopId=" + shopId
                        )
                    );
        }
        /// <summary>
        /// 创建客户订单
        /// </summary>
        /// <param name="skuId"></param>
        /// <param name="mobile"></param>
        /// <param name="size"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public static RetailUserOrderDTO createRetailOrder(String skuId,String mobile,String size,int quantity)
        {
            return
                FunctionHelper.JsonDeserialization<RetailUserOrderDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/createRetailOrder?skuId=" + skuId + "&mobile=" + mobile + "&size=" + size + "&quantity=" + quantity
                    )
                );
        }
        /// <summary>
        /// 取得未发货订单
        /// </summary>
        /// <returns></returns>
        public static List<RetailUserOrderDTO> getUnDeliveryUserOrder(String orgId, String shopId)
        {
            return
                FunctionHelper.JsonDeserialization<List<RetailUserOrderDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url1 + "/douyin/getUnDeliveryUserOrder?orgId=" + orgId + "&shopId=" + shopId
                        )
                    );
        }

        /// <summary>
        /// 更新订单为已发货
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public static String setRetailOrderDelivery(List<String> ids)
        {
            return
                RestCall.PostHttp(
                    URL.接口url1 + "/douyin/setRetailOrderDelivery",
                    FunctionHelper.JsonSerialization(ids)
                );
        }
        /// <summary>
        /// 删除零售订单
        /// </summary>
        /// <param name="id"></param>
        public static String deleteRetailOrderById(String id)
        {
            return
                RestCall.httpGetMethod(
                    URL.接口url1 + "/douyin/deleteRetailOrderById?id=" + id
                );
        }
    }
    public class RetailSkuDTO
    {
        public String skuId { get; set; }
        public String description { get; set; }    //  描述
        public String pictureUrl { get; set; } //   图片
        public Boolean ifRemove { get; set; } // 是否下架
        public Boolean ifPreSale { get; set; } //    是否预售
        public Double price { get; set; } //    单价
        public DateTime createDate { get; set; } //  上架时间
        public String orgId { get; set; }   //  来源组织id，也就是获客渠道
        public String shopId { get; set; }  //  门店id

        public List<RetailOrderDTO> retailOrderDTOList { get; set; }
        public RetailSkuDTO()
        {

        }
    }
    public class RetailOrderDTO
    {
        public String id { get; set; }
        public String skuId { get; set; }   //  商品
        public Double actualPayment { get; set; } //    实付单价
        public Boolean ifDelivery { get; set; } // 是否发货
        public DateTime orderDate { get; set; } //  下单日期
        //  客户详细信息
        public String mobile { get; set; }  //  电话
        public String customerName { get; set; }
        public String addressProvince { get; set; } //  省
        public String addressCity { get; set; } //  市
        public String addressDistrict { get; set; } //  区
        public String addressDetail { get; set; }// 详细地址
        public String size { get; set; }    //  尺码
        public int quantity { get; set; } //   数量
        public RetailOrderDTO()
        {

        }
    }
    public class RetailUserOrderDTO
    {
        public String id { get; set; }  //  id
        public String mobile { get; set; }  //  电话
        public String customerName { get; set; }
        public Double actualPayment { get; set; } //    实付单价
        public Boolean ifDelivery { get; set; } // 是否发货
        public DateTime orderDate { get; set; } //  下单日期
        public String size { get; set; }    //  尺码
        public int quantity { get; set; } //   数量
        public String skuId { get; set; }    //  skuId

        public String description { get; set; }    //  描述
        public RetailUserOrderDTO()
        {

        }
    }
}
